<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>订单记录管理</title>
<link rel="stylesheet" type="text/css" href="/secondhand/css/query.css" />
<script type="text/javascript" src="/secondhand/js/jquery-3.2.1.js"></script>
	<script type="text/javascript">
		$(function () {
			var param = new URLSearchParams(window.location.search);
			var pageNo = param.get("pageNo");
			var likeValue = param.get("likeValue");
			selectByPage(pageNo,likeValue);
			//点击查询按钮
			$("#selectByLikeValue").click(function () {
				var likeValueStr = $.trim($("#likeValueStr").val());//去除空格
				selectByPage(1,likeValueStr);
			})
		})
		function selectByPage(pageNo,likeValue){
			var url = "/secondhand/selectByPage.order";
			var paramObj = {
				"pageNo":pageNo,"likeValue":likeValue};
			$.post(url,paramObj,function (data) {
				if (data == "") {
					window.parent.location.href = "/secondhand/login.html"
				}
				$("#tbodyList").empty();
				var jsonObj = JSON.parse(data);
				var recordList = jsonObj.recordList;
				for (var i = 0; i < recordList.length; i++) {
					$("<tr><td>"+recordList[i].orderid+"</td><td>"
							+recordList[i].goodsname+"</td><td>"
							+recordList[i].goodsprice+"</td><td>"
							+recordList[i].buyerid+"</td><td>"
							+recordList[i].salerid+"</td><td>"
							+recordList[i].createtime+"</td><td>"
							+recordList[i].orderstatus+"</td><td>"
							+recordList[i].address+
							"</td><td><a href='/secondhand/deleteById.order?orderid="+recordList[i].orderid+"' onclick='confirmDelete(this)'>删除</a></td></tr>").appendTo($("#tbodyList"));
				}
				$("#likeValueStr").val(jsonObj.likeValue);//回填查询条件
				$("#recordCount").text(jsonObj.recordCount);//总记录数
				$("#totalPages").text(jsonObj.totalPages);//总页数
				$("#pageNo").text(jsonObj.pageNo);//当前页数

				$("#firstPage").prop("href","/secondhand/toList.order?pageNo=1&likeValue="+jsonObj.likeValue)//首页
				if(jsonObj.pageNo!=1)
					$("#prevPage").prop("href","/secondhand/toList.order?pageNo="+(jsonObj.pageNo-1)+"&likeValue="+jsonObj.likeValue)//上一页
				if(jsonObj.pageNo!=jsonObj.totalPages)
					$("#nextPage").prop("href","/secondhand/toList.order?pageNo="+(jsonObj.pageNo+1)+"&likeValue="+jsonObj.likeValue)//下一页
				$("#lastPage").prop("href","/secondhand/toList.order?pageNo="+jsonObj.totalPages+"&likeValue="+jsonObj.likeValue)//尾页
			})
		}
		function confirmDelete(aNode){
			var orderid = $(aNode).parent().parent().find("td").eq(0).text();
			if (!confirm("确定删除订单号为"+orderid+"的订单记录吗？")){
				event.preventDefault();//阻止控件默认行为
			}
		}
	</script>
</head>
<body>
	<div id="top">·当前位置： 购物管理 -- 查看订单记录</div>
	<div id="contexttop">
		<table id="tab" border="1" style="width: 90%;">
			<tr>
				<td colspan="7" height="50px">
						<input type="text" id="likeValueStr" title="商品名称、价格" placeholder="商品名称、价格" />
						<input type="submit" value="查询" id="selectByLikeValue" />
				</td>
			</tr>
			<tr bgcolor="#cccccc">
				<th>订单编号</th>
				<th>商品名称</th>
				<th>价格</th>
				<th>购买者</th>
				<th>售出者</th>
				<th>下单时间</th>
				<th>发货状态</th>
				<th>收获地址</th>
				<th>操作</th>
			</tr>
			<tbody id="tbodyList">
			</tbody>
		</table>
	</div>
	<div align="center" id="contextbotton">
		&nbsp;总记录数&nbsp;<span id="recordCount"></span>&nbsp;条&nbsp;共&nbsp;<span id="totalPages"></span>&nbsp;页 &nbsp;
		<a id="firstPage" href="">首页</a>&nbsp;
		<a id="prevPage" href="">上一页</a> &nbsp;
		<a id="nextPage" href="">下一页</a> &nbsp;
		<a id="lastPage" href="">尾页</a>
		&nbsp;第&nbsp;<span id="pageNo"></span>&nbsp;页&nbsp;
	</div>
</body>
</html>